<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="区号" prop="countryCode">
        <el-input
          v-model="queryParams.countryCode"
          placeholder="请输入区号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短信模板id" prop="templateId">
        <el-input
          v-model="queryParams.templateId"
          placeholder="请输入短信模板id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="from_where" prop="fromWhere">
        <el-input
          v-model="queryParams.fromWhere"
          placeholder="请输入from_where"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发送时间" prop="reqTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.reqTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择发送时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="响应时间" prop="resTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.resTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择响应时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="bulk_id" prop="bulkId">
        <el-input
          v-model="queryParams.bulkId"
          placeholder="请输入bulk_id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短信渠道id" prop="msgId">
        <el-input
          v-model="queryParams.msgId"
          placeholder="请输入短信渠道id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="sendStatus">
        <el-select v-model="queryParams.sendStatus" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:sms_send_log:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:sms_send_log:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:sms_send_log:remove']"
        >删除
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:sms_send_log:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

     <el-table v-loading="loading" :data="sms_send_logList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="序号" align="center" prop="id" />
          <el-table-column label="区号" align="center" prop="countryCode" />
          <el-table-column label="手机号" align="center" prop="phoneNumber" width="115" />
          <el-table-column label="短信模板id" width="85" align="center" prop="templateId" />
          <el-table-column label="短信发送方式" align="center" prop="smsType" width="150" />
          <el-table-column label="短信发送渠道方式" align="center" prop="noticeType" width="140" />
          <el-table-column label="短信内容" align="center" prop="content" min-width="240" />
          <el-table-column label="from_where" align="center" prop="fromWhere" width="120" />
          <el-table-column label="发送时间" align="center" prop="reqTime" width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime}}</span>
            </template>
          </el-table-column>
          <el-table-column label="响应时间" align="center" prop="resTime" width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.updateTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="bulk_id" align="center" prop="bulkId" />
          <el-table-column label="短信渠道id" align="center" prop="msgId" width="120" />
          <el-table-column label="状态" align="center" prop="sendStatus" min-width="180"/>
          <el-table-column label="错误信息" align="center" prop="errMsg" />
          <el-table-column label="备注" align="center" prop="remark" min-width="280" />
          <!-- <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['business:sms_send_log:edit']">修改
              </el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['business:sms_send_log:remove']">删除
              </el-button>
            </template>
          </el-table-column> -->
        </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改短信发送日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="区号" prop="countryCode">
          <el-input v-model="form.countryCode" placeholder="请输入区号"/>
        </el-form-item>
        <el-form-item label="手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号"/>
        </el-form-item>
        <el-form-item label="短信模板id" prop="templateId">
          <el-input v-model="form.templateId" placeholder="请输入短信模板id"/>
        </el-form-item>
        <el-form-item label="短信内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="from_where" prop="fromWhere">
          <el-input v-model="form.fromWhere" placeholder="请输入from_where"/>
        </el-form-item>
        <el-form-item label="发送时间" prop="reqTime">
          <el-date-picker clearable size="small"
                          v-model="form.reqTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择发送时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="响应时间" prop="resTime">
          <el-date-picker clearable size="small"
                          v-model="form.resTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择响应时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="bulk_id" prop="bulkId">
          <el-input v-model="form.bulkId" placeholder="请输入bulk_id"/>
        </el-form-item>
        <el-form-item label="短信渠道id" prop="msgId">
          <el-input v-model="form.msgId" placeholder="请输入短信渠道id"/>
        </el-form-item>
        <el-form-item label="状态" prop="sendStatus">
          <el-select v-model="form.sendStatus" placeholder="请选择状态">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="错误信息" prop="errMsg">
          <el-input v-model="form.errMsg" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listSms_send_log, getSms_send_log, delSms_send_log, addSms_send_log, updateSms_send_log, exportSms_send_log} from "@/api/business/sms_send_log";
import Editor from '@/components/Editor';

export default {
  name: "Sms_send_log",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 短信发送日志表格数据
      sms_send_logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        countryCode: null,
        phoneNumber: null,
        templateId: null,
        content: null,
        fromWhere: null,
        reqTime: null,
        resTime: null,
        bulkId: null,
        msgId: null,
        sendStatus: null,
        errMsg: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        phoneNumber: [
          {required: true, message: "手机号不能为空", trigger: "blur"}
        ],
        content: [
          {required: true, message: "短信内容不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
        updateTime: [
          {required: true, message: "更新时间不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    /** 查询短信发送日志列表 */
    getList() {
      this.loading = true;
      listSms_send_log(this.queryParams).then(response => {
        this.sms_send_logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        countryCode: null,
        phoneNumber: null,
        templateId: null,
        content: null,
        fromWhere: null,
        reqTime: null,
        resTime: null,
        bulkId: null,
        msgId: null,
        sendStatus: null,
        errMsg: null,
        remark: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加短信发送日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSms_send_log(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改短信发送日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSms_send_log(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSms_send_log(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除短信发送日志编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delSms_send_log(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有短信发送日志数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportSms_send_log(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
<style type="text/css" scoped>
  .el-table td.el-table__cell div {
    word-break: break-word !important;
  }
</style>
